package com.lost.octopus.es.helper.entity.wrapper;

import com.lost.octopus.es.helper.entity.model.FieldConfig;
import com.lost.octopus.es.helper.constant.EsMatchType;

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 多个值的前缀查询
 * 同sql and ( fieldName like  xx% or fieldName like  xx1% )
 * <br/>
 * 注解：{@code @EsSearch(queryType = EsQueryMultiplyValPrefixWrapper.class, fieldName = "xzqh")}
 * <br/>
 * 示例：{@code "350212,350211"}
 * <br/>
 * 效果：{@code {"bool":{"should":[{"prefix":{"xzqh":{"value":"350212"}}},{"prefix":{"xzqh":{"value":"350211"}}}]}} }
 * @author zhangbh
 **/
@Component
public class EsQueryMultiplyValPrefixWrapper extends AbstractQueryWrapper  {

    @Resource
    private EsQueryMultiplyValWrapper multiplyValWrapper;

    @Override
    public QueryBuilder addWrapper(BoolQueryBuilder builder, FieldConfig field) {
        FieldConfig changeQuery = field.copy().setMatchType(EsMatchType.prefix);
        return multiplyValWrapper.addWrapper(builder, changeQuery);
    }
}
